/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.system.impl;

import dao.system.SystemMenuDao;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import model.system.SystemMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.system.SystemMenuService;
import utility.NameValueList;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
@Service("systemMenuService")
@Transactional(readOnly=true)
public class SystemMenuServiceImpl implements SystemMenuService{

    @Autowired private SystemMenuDao systemMenuDao;
    @Transactional(readOnly=false)
    @Override
    public SystemMenu getSystemMenu(int id) {
         return systemMenuDao.getById(id);
    }
    
    @Override
    public List<SystemMenu> getSystemMenu() {
        return systemMenuDao.getAll();
    }

    @Override
    public List<SystemMenu> getSystemMenu(int start, int num) {
        return systemMenuDao.getAll(start, num);
    }

    @Override
    public List<SystemMenu> getAll(int start, int num, String params, String orderBy) {
        return systemMenuDao.getAll(start, num, params, orderBy);
    }
    
    @Override
    public DefaultComboBoxModel<SystemMenu> getModules(String params, String orderBy, boolean withAll) {
        DefaultComboBoxModel rs=new DefaultComboBoxModel();
        
       // if (params==null)
          //  params = "";
        params = " where menu_type = 'root'";
        List<SystemMenu> menus = this.getAll(0, 1000, params, orderBy);
        if (withAll)
            rs.addElement(new NameValueList("-1", "Semua"));
        for (SystemMenu menu : menus){
            //
            rs.addElement(new NameValueList(String.valueOf(menu.getMenuId()), menu.getMenuName()));
        }
        return rs; 
    }

   
}
